﻿Public Partial Class NovoUsuario
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Util.EhVazioNull(Session("IdUsuario")) Then
            Response.Redirect("Login.aspx")
        End If
        VerificaUsuarioAdmin()
    End Sub

    Protected Sub btnGravar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGravar.Click
        Dim ta As DataSet1TableAdapters.UsuarioTableAdapter = New DataSet1TableAdapters.UsuarioTableAdapter
        Dim table As DataSet1.UsuarioDataTable = New DataSet1.UsuarioDataTable
        Dim row As DataSet1.UsuarioRow = table.NewRow()
        row.Login = txtLogin.Text.Trim.ToLower
        row.Senha = txtSenha.Text.Trim.GetHashCode
        table.Rows.Add(row)
        ta.Update(table)
        Response.Redirect("Home.aspx")
    End Sub

    Protected Sub VerificaUsuarioAdmin()
        'HASH DE 123456 EH 1849190365
        Dim ta As DataSet1TableAdapters.UsuarioTableAdapter = New DataSet1TableAdapters.UsuarioTableAdapter
        Dim table As DataSet1.UsuarioDataTable
        table = ta.GetDataByIdUsuario(Session("IdUsuario"))
        If table.Rows(0).Item("Login") <> "admin" Then
            Response.Redirect("Home.aspx")
        End If
    End Sub

End Class